XMas.Preloader = function(game){
};

XMas.Preloader.prototype = {
    preload: function(){
        // set background color and preload image
        var self = this;
        self.add.image(0, 0, 'bg_loading');
        self.preloadBar = this.add.sprite((XMas.GlobalVariables.GAME_WIDTH-250)/2, (XMas.GlobalVariables.GAME_HEIGHT)/2, 'preloaderBar');
        self.preloadBar.animations.add('loading');
        self.preloadBar.animations.play('loading', 5, true);

        // load images
        self.load.image('background', XMas.Config.setting.backGroundUrl);
        self.load.image('backgroundMain', XMas.Config.setting.backGroundMainUrl);
        this.load.image("blackfade", "assets/blackfade.png");
        this.load.image("blackfade1", "assets/blackfade1.png");
        this.load.image("light1", "assets/light1.png");
        this.load.image("light2", "assets/light2.png");
        this.load.image("light3", "assets/light3.png");
        this.load.image("gameover_text", "assets/gameover_text.png");
        //load item images
        XMas.Config.items.forEach(function(item){
            self.load.image('res_item_'+item.keyID,item.imageUrl,50,50);
        });
         self.load.image('res_item_shell',XMas.Config.setting.itemShell);
        //load santa images
        XMas.Config.santas.forEach(function(item){
            self.load.spritesheet('res_santa_'+item.keyID,item.imageUrl,151,196,40);
        });
        self.load.spritesheet('res_santa_patient','assets/santapatient.png',66,17,5);
        //load gifts
        XMas.Config.giftItems.forEach(function(item){
            self.load.spritesheet('res_gift_explosion_'+item.keyID,item.imageExplosionUrl,328,328);
            self.load.audio('res_sound_gift_click_' + item.keyID, item.clickedSound);
            XMas.gift_clickedSound[item.keyID] = self.add.audio('res_sound_gift_click_' + item.keyID, 1, false);
        });
        self.load.spritesheet('res_gift_green_spritesheet','assets/gift03.png',70,70,8);
        self.load.spritesheet('res_gift_pink_spritesheet','assets/gift01.png',70,70,8);
        self.load.spritesheet('res_gift_violet_spritesheet','assets/gift02.png',70,70,8);
        self.load.spritesheet('res_gift_red_spritesheet','assets/gift04.png',70,70,8);
        //load thinking
        self.load.image('res_common_thinking','assets/thinking.png',120,113);
        // load spritesheets
        self.load.spritesheet('button-start', 'assets/button-start.png', 190, 70, 8);
        self.load.spritesheet('button-try', 'assets/button-try.png', 190, 70, 8);
        
        // load the games main music
        self.load.audio('bgMusic', XMas.soundBackground);
        XMas.backgroundMusic = self.add.audio('bgMusic', 1, true);
         self.load.audio('bgLevelUp', 'assets/Audio/bg/levelup.mp3');
         XMas.backgroundLevelUp = self.add.audio('bgLevelUp', 1, false);
        XMas.Config.setting.soundSantaRequestCorrect.forEach(function(item){
            self.load.audio('res_sound_santa_req_correct_' + item.keyID, item.soundUrl);
            XMas.santa_Correct[item.keyID] = self.add.audio('res_sound_santa_req_correct_' + item.keyID, 1, false);
        });
        XMas.Config.setting.soundSantaRequestIncorrect.forEach(function(item){
            self.load.audio('res_sound_santa_req_incorrect_' + item.keyID, item.soundUrl);
            XMas.santa_Incorrect[item.keyID] = self.add.audio('res_sound_santa_req_incorrect_' + item.keyID, 1, false);
        });
        //load image of logoText array
        XMas.Config.setting.logoText.forEach(function (item) {
            self.load.image('logo_' + item.keyID, item.imageUrl);
        });
        //load snow
        self.game.load.spritesheet('res_snowflakesImg', XMas.Config.setting.snowflakesImgUrl, 46, 46,8);
    },
    create: function(){
        // start the MainMenu state
       this.state.start('MainMenu');
    }
};